package com.java.service.impl;

import com.github.pagehelper.PageHelper;
import com.java.entity.TeacherLevel;
import com.java.mapper.TeacherLevelMapper;
import com.java.service.TeacherLevelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class TeacherLevelServiceImpl implements TeacherLevelService {

    @Autowired
    private TeacherLevelMapper teacherLevelMapper;

    @Override
    public int insert(TeacherLevel teacherLevel) {
        return teacherLevelMapper.insertSelective(teacherLevel);
    }

    @Override
    public int delete(Integer teacherLevelId) {
        return teacherLevelMapper.deleteByPrimaryKey(teacherLevelId);
    }

    @Override
    public int update(TeacherLevel teacherLevel) {
        return teacherLevelMapper.updateByPrimaryKeySelective(teacherLevel);
    }

    @Override
    public TeacherLevel selectOne(Integer teacherLevelId) {
        TeacherLevel teacherLevel = teacherLevelMapper.selectByPrimaryKey(teacherLevelId);
        if (teacherLevel == null) {
            throw new RuntimeException("teacherLevel is null, teacherLevelId=" + teacherLevelId);
        }
        return teacherLevel;
    }

    @Override
    public List<TeacherLevel> selectAll() {
        return teacherLevelMapper.selectByExample(null);
    }

    @Override
    public List<TeacherLevel> selectByPage(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize, true, true, false);
        return teacherLevelMapper.selectByExample(null);
    }

}
